 

import { reactive } from 'vue'
import * as Fields from '../fields/index'
import type { IJsonItem, INodeData, ITaskData } from '../types'

export function useMlflow({
  projectCode,
  from = 0,
  readonly,
  data
}: {
  projectCode: number
  from?: number
  readonly?: boolean
  data?: ITaskData
}) {
  const model = reactive({
    name: '',
    taskType: 'MLFLOW',
    flag: 'YES',
    description: '',
    timeoutFlag: false,
    localParams: [],
    environmentCode: null,
    failRetryInterval: 1,
    failRetryTimes: 0,
    workerGroup: 'default',
    algorithm: 'svm',
    mlflowTrackingUri: 'http://127.0.0.1:5000',
    mlflowTaskType: 'MLflow Projects',
    deployType: 'MLFLOW',
    deployPort: '7000',
    mlflowJobType: 'CustomProject',
    automlTool: 'flaml',
    mlflowCustomProjectParameters: [],
    delayTime: 0,
    timeout: 30,
    timeoutNotifyStrategy: ['WARN']
  } as INodeData)

  return {
    json: [
      Fields.useName(from),
      ...Fields.useTaskDefinition({ projectCode, from, readonly, data, model }),
      Fields.useRunFlag(),
      Fields.useDescription(),
      Fields.useTaskPriority(),
      Fields.useWorkerGroup(),
      Fields.useEnvironmentName(model, !model.id),
      ...Fields.useTaskGroup(model, projectCode),
      ...Fields.useFailed(),
      Fields.useDelayTime(model),
      ...Fields.useTimeoutAlarm(model),
      ...Fields.useMlflow(model),
      Fields.usePreTasks()
    ] as IJsonItem[],
    model
  }
}
